package com.order.service.impl;

import com.order.exception.CustomException;
import com.order.service.SessionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class SessionServiceImpl implements SessionService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public String getSession() throws CustomException {
        String sessionid=UUID.randomUUID().toString();
        logger.info("SessionId:{}",sessionid);
        redisTemplate.opsForValue().set("SessionId",sessionid,600, TimeUnit.SECONDS);
        return sessionid;
    }
}
